FROM php:8.4.12-zts-alpine

# 使用国内镜像源
RUN sed -i 's#https\?://dl-cdn.alpinelinux.org/alpine#https://mirrors.tuna.tsinghua.edu.cn/alpine#g' /etc/apk/repositories

RUN apk update
# autoconf dpkg-dev dpkg file g++ gcc libc-dev make pkgconf re2c
RUN set -eux; \
    apk add --no-cache libcurl c-ares zstd  curl unzip libzip brotli openssl dpkg postgresql-libs sqlite-libs; \
    apk add --no-cache --virtual .build-deps libzip-dev openssl-dev pkgconfig $PHPIZE_DEPS brotli-dev curl-dev sqlite-dev postgresql-dev; \
    pecl install -n redis; \
    pecl install  brotli; \
    docker-php-ext-enable redis brotli; \
    pecl install -n -D 'enable-sockets="no" enable-mysqlnd="no" enable-iouring="no" with-swoole-odbc="no" enable-openssl="yes" enable-swoole-curl="yes" enable-cares="yes" enable-swoole-pgsql="yes"  with-swoole-oracle="no" enable-swoole-sqlite="yes" enable-swoole-thread="yes" enable-zstd="yes" enable-brotli="yes"' swoole; \
    docker-php-ext-enable swoole; \
    docker-php-ext-install -j$(nproc) pdo_mysql mysqli pcntl zip; \
    apk del --no-network .build-deps; \
    rm -rf /var/cache/apk/* /tmp/* /var/tmp/*



# 合并脚本复制和权限设置
COPY docker/services/php/wait-for-it.sh /usr/local/bin/
COPY docker/services/php/docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/wait-for-it.sh /usr/local/bin/docker-entrypoint.sh

WORKDIR /var/www

# 合并 Composer 安装步骤
RUN curl -sS https://getcomposer.org/installer | php && \
    mv composer.phar /usr/local/bin/composer && \
    composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

EXPOSE 9501

ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["php", "bin/console", "server:start"]
